package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerDao customerDao;

    @Override
    public Page<Customer> page(Integer page, Integer rows, String customerName) {
        PageHelper.startPage(page,rows);
        Page<Customer> page1 = customerDao.page(page,rows,customerName);
//        Map<String,Object> map = new HashMap<>();
//        map.put("total",page1.getTotal());
//        map.put("rows",page1.getResult());
        return page1;
    }

    @Override
    public void save(Customer customer) {
        customerDao.save(customer);
    }

    @Override
    public void update(Customer customer, Integer customerId) {
        customerDao.update(customer,customerId);
    }

    @Override
    public void delete(String ids) {
        String[] id = ids.split(",");
        customerDao.delete(id);
    }
}
